<?php
require_once("../include/main.php");
if(!isset($_SESSION['id'])){
	echo "error";
	die();
}
if(isset($_GET['op'])) {
	switch($_GET['op']) {
		case 'index':
			$result = $db->query('select * from room');
			//print_r($result);
			echo json_encode($result);
			break;
		case 'create':
			if(isset($_POST)) {
				//print_r($_POST);
				$name = $_POST['r_name'];
				$vol = $_POST['r_vol'];
				$media = $_POST['r_media'];
				$sql = "INSERT INTO room (title, num, media) VALUES ('".$name."',".$vol.",".$media.")";
				//print $sql;
				$r = $db->execute($sql);
				if($r) echo "添加成功！";
			}
			break;
		case 'update':
			break;
		case 'delete':
			break;
	}
}